* Table 3: Marriage and Rank-Rank Mobility in the 1948-1953 and 1961-1964 Cohorts
* Table A14: Marriage and Log Income Mobility in the 1948-1953 and 1961-1964 Cohorts
* Table A15: Marriage and Intergenerational Mobility in the 1948-1953 and 1961-1964 Cohorts, Parent-Daughter Pairs
* Table A16: Marriage and Intergenerational Mobility in the 1948-1953 and 1961-1964 Cohorts, Parent-Son Pairs

clear
use "${data_dir}DavisMazumderData.dta"

* Sample Restrictions 
keep if age_firstSurvey<=18
drop if miss0 | miss1
drop if (mom_outOfRange==1 & linkMom==1 & !(dad_outOfRange==0 & linkDad==1)) | (dad_outOfRange==1 & linkDad==1 & !(mom_outOfRange==0 & linkMom==1)) | (linkMom==0 & linkDad==0) 
 

* Generate income ranks after applying sample restrictions
gen N = .
 tab n  if surv79==0 & women==0  [w=weight]
 replace N = r(N) if surv79==0 & women==0 
 tab n  if surv79==0 & women==1   [w=weight]
 replace N = r(N) if surv79==0 & women==1 
 tab n  if surv79==1 & women==0   [w=weight]
 replace N = r(N) if surv79==1 & women==0 
 tab n  if surv79==1 & women==1 [w=weight]
 replace N = r(N) if surv79==1 & women==1 
 
* Family Income Rank in Parent Generation
set sortseed 6688571
sort women surv79 faminc0
by women surv79: gen __rank0 = sum(weight) 
gen _rank0 = __rank0/N 
by women surv79 faminc0: egen rank0 = mean(_rank0) 
 replace rank0 = 100*rank0
gen perc66 = rank0*(1-surv79)
gen perc79 = rank0*surv79

 
* Family Income Rank in Kid Generation
set sortseed 6688571
sort women surv79 faminc1
by women surv79: gen __rank1 = sum(weight)
gen _rank1 = __rank1/N 
bys women surv79 faminc1: egen rank1 = mean(_rank1) 
replace rank1 = 100*rank1

drop N __rank0 _rank0 __rank1 _rank1 



* Own Income Rank in Kid Generation
gen N = .
 tab n  if surv79==0 & women==0   & miss1_l750==0 [w=weight]
 replace N = r(N) if surv79==0 & women==0   & miss1_l750==0
 tab n  if surv79==0 & women==1     & miss1_l750==0 [w=weight]
 replace N = r(N) if surv79==0 & women==1    & miss1_l750==0
 tab n  if surv79==1 & women==0     & miss1_l750==0 [w=weight]
 replace N = r(N) if surv79==1 & women==0    & miss1_l750==0
 tab n  if surv79==1 & women==1    & miss1_l750==0 [w=weight]
 replace N = r(N) if surv79==1 & women==1    & miss1_l750==0


gen owninc_nm = owninc
replace owninc_nm = . if !(miss1_l750==0 )
set sortseed 6688571
sort women surv79 owninc_nm
by women surv79: gen __ownrank = sum(weight) if miss1_l750==0
gen _ownrank = __ownrank/N if miss1_l750==0
bys women surv79 owninc_nm: egen ownrank = mean(_ownrank) if miss1_l750==0
replace ownrank = 100*ownrank


drop N   __ownrank _ownrank owninc_nm 



 * Parent Decile Indicators
gen decile0 = 1 if rank0<=10
 replace decile0 = 2 if rank0>10 & rank0<=20
 replace decile0 = 3 if rank0>20 & rank0<=30
 replace decile0 = 4 if rank0>30 & rank0<=40
 replace decile0 = 5 if rank0>40 & rank0<=50
 replace decile0 = 6 if rank0>50 & rank0<=60
 replace decile0 = 7 if rank0>60 & rank0<=70
 replace decile0 = 8 if rank0>70 & rank0<=80
 replace decile0 = 9 if rank0>80 & rank0<=90
 replace decile0 = 10 if rank0>90 & rank0<=100
 
 
 
 


* Married Always
reg married perc66 perc79 surv79  women [w=weight], cluster(hhid)
eststo married
test perc79=perc66
estadd scalar p = r(p): married
gen s=e(sample)
count if surv79==0 & s==1
estadd scalar N66 = r(N): married
count if surv79==1 & s==1
estadd scalar N79 = r(N): married
lincom perc79-perc66
estadd scalar diff = r(estimate): married
estadd scalar se = r(se): married
drop s


reg married perc66 perc79 surv79 if women==1 [w=weight], cluster(hhid)
eststo married_w
test perc79=perc66
estadd scalar p = r(p): married_w
gen s=e(sample)
count if surv79==0 & s==1
estadd scalar N66 = r(N): married_w
count if surv79==1 & s==1
estadd scalar N79 = r(N): married_w
lincom perc79-perc66
estadd scalar diff = r(estimate): married_w
estadd scalar se = r(se): married_w
drop s


reg married perc66 perc79 surv79 if women==0 [w=weight], cluster(hhid)
eststo married_m
test perc79=perc66
estadd scalar p = r(p): married_m
gen s=e(sample)
count if surv79==0 & s==1
estadd scalar N66 = r(N): married_m
count if surv79==1 & s==1
estadd scalar N79 = r(N): married_m
lincom perc79-perc66
estadd scalar diff = r(estimate): married_m
estadd scalar se = r(se): married_m
drop s



reg married loginc66 loginc79 surv79  women [w=weight], cluster(hhid)
eststo married_ige
test loginc66=loginc79
estadd scalar p = r(p): married_ige
gen s=e(sample)
count if surv79==0 & s==1
estadd scalar N66 = r(N): married_ige
count if surv79==1 & s==1
estadd scalar N79 = r(N): married_ige
lincom loginc79-loginc66
estadd scalar diff = r(estimate): married_ige
estadd scalar se = r(se): married_ige
drop s

reg married loginc66 loginc79 surv79  if women==1 [w=weight], cluster(hhid)
eststo married_ige_w
test loginc66=loginc79
estadd scalar p = r(p): married_ige_w
gen s=e(sample)
count if surv79==0 & s==1
estadd scalar N66 = r(N): married_ige_w
count if surv79==1 & s==1
estadd scalar N79 = r(N): married_ige_w
lincom loginc79-loginc66
estadd scalar diff = r(estimate): married_ige_w
estadd scalar se = r(se): married_ige_w
drop s

reg married loginc66 loginc79 surv79  if women==0 [w=weight], cluster(hhid)
eststo married_ige_m
test loginc66=loginc79
estadd scalar p = r(p): married_ige_m
gen s=e(sample)
count if surv79==0 & s==1
estadd scalar N66 = r(N): married_ige_m
count if surv79==1 & s==1
estadd scalar N79 = r(N): married_ige_m
lincom loginc79-loginc66
estadd scalar diff = r(estimate): married_ige_m
estadd scalar se = r(se): married_ige_m
drop s


* Ever Married (Mentioned in text)
gen ever_married = 100*(share_married>0) if share_married<.
reg ever_married perc66 perc79 surv79  women [w=weight], cluster(hhid)


* Re-weight to match NLS66
gen p_m66 = .
gen p_m79 = .

replace married = 1 if married==100

forv women=0/1 {
		forv decile = 1/10 {
			qui su married if women==`women' & surv79==0 & decile==`decile' [w=weight]
			replace p_m66 = r(mean) if women==`women' & decile==`decile'
			qui su married if women==`women' & surv79==1 & decile==`decile' [w=weight]
			replace p_m79 = r(mean) if women==`women' & decile==`decile'
	}
}

gen rewt_marr = .
 replace rewt_marr = weight if surv79==0
 replace rewt_marr = (p_m66/p_m79)*weight if married==1 & surv79==1
 replace rewt_marr = ((1-p_m66)/(1-p_m79))*weight if married==0 & surv79==1
 
su married if survey==1966 & women==1 [w=rewt_marr]
su married if survey==1979 & women==1 [w=rewt_marr]
replace married = 100*married


* Married Always (Re-weight check)
reg married perc66 perc79 surv79  women [w=rewt_marr], cluster(hhid)
eststo married_rewt
test perc79=perc66
estadd scalar p = r(p): married_rewt
gen s=e(sample)
count if surv79==0 & s==1
estadd scalar N66 = r(N): married_rewt
count if surv79==1 & s==1
estadd scalar N79 = r(N): married_rewt
lincom perc79-perc66
estadd scalar diff = r(estimate): married_rewt
estadd scalar se = r(se): married_rewt
drop s

reg married perc66 perc79 surv79 if women==1 [w=rewt_marr], cluster(hhid)
eststo married_rewt_w
test perc79=perc66
estadd scalar p = r(p): married_rewt_w
gen s=e(sample)
count if surv79==0 & s==1
estadd scalar N66 = r(N): married_rewt_w
count if surv79==1 & s==1
estadd scalar N79 = r(N): married_rewt_w
lincom perc79-perc66
estadd scalar diff = r(estimate): married_rewt_w
estadd scalar se = r(se): married_rewt_w
drop s

reg married perc66 perc79 surv79 if women==0 [w=rewt_marr], cluster(hhid)
eststo married_rewt_m
test perc79=perc66
estadd scalar p = r(p): married_rewt_m
gen s=e(sample)
count if surv79==0 & s==1
estadd scalar N66 = r(N): married_rewt_m
count if surv79==1 & s==1
estadd scalar N79 = r(N): married_rewt_m
lincom perc79-perc66
estadd scalar diff = r(estimate): married_rewt_m
estadd scalar se = r(se): married_rewt_m
drop s

* Reweight IGE
reg married loginc66 loginc79 surv79  women [w=rewt_marr], cluster(hhid)
eststo married_ige_rewt
test loginc66=loginc79
estadd scalar p = r(p): married_ige_rewt
gen s=e(sample)
count if surv79==0 & s==1
estadd scalar N66 = r(N): married_ige_rewt
count if surv79==1 & s==1
estadd scalar N79 = r(N): married_ige_rewt
lincom loginc79-loginc66
estadd scalar diff = r(estimate): married_ige_rewt
estadd scalar se = r(se): married_ige_rewt
drop s
 
reg married loginc66 loginc79 surv79 if women==1 [w=rewt_marr], cluster(hhid)
eststo married_ige_rewt_w
test loginc66=loginc79
estadd scalar p = r(p): married_ige_rewt_w
gen s=e(sample)
count if surv79==0 & s==1
estadd scalar N66 = r(N): married_ige_rewt_w
count if surv79==1 & s==1
estadd scalar N79 = r(N): married_ige_rewt_w
lincom loginc79-loginc66
estadd scalar diff = r(estimate): married_ige_rewt_w
estadd scalar se = r(se): married_ige_rewt_w
drop s
 
 
reg married loginc66 loginc79 surv79 if women==0 [w=rewt_marr], cluster(hhid)
eststo married_ige_rewt_m
test loginc66=loginc79
estadd scalar p = r(p): married_ige_rewt_m
gen s=e(sample)
count if surv79==0 & s==1
estadd scalar N66 = r(N): married_ige_rewt_m
count if surv79==1 & s==1
estadd scalar N79 = r(N): married_ige_rewt_m
lincom loginc79-loginc66
estadd scalar diff = r(estimate): married_ige_rewt_m
estadd scalar se = r(se): married_ige_rewt_m
drop s
  
 
* Reweighed ranks
* Rank Mobility


replace rewt_marr = round(rewt_marr)

gen N = .
 tab n  if surv79==0 & women==0 & miss0==0 & miss1==0 [w=rewt_marr]
 replace N = r(N) if surv79==0 & women==0 & miss0==0 & miss1==0
 tab n  if surv79==0 & women==1  & miss0==0 & miss1==0 [w=rewt_marr]
 replace N = r(N) if surv79==0 & women==1 & miss0==0 & miss1==0
 tab n  if surv79==1 & women==0  & miss0==0 & miss1==0 [w=rewt_marr]
 replace N = r(N) if surv79==1 & women==0 & miss0==0 & miss1==0
 tab n  if surv79==1 & women==1 & miss0==0 & miss1==0 [w=rewt_marr]
 replace N = r(N) if surv79==1 & women==1 & miss0==0 & miss1==0
 
* Family Income Rank in Parent Generation
gen faminc0_nm = faminc0
replace faminc0_nm = . if !(miss0==0 & miss1==0)
set sortseed 6688571
sort women surv79 faminc0_nm
by women surv79: gen __rank0_rewt = sum(rewt_marr) if  miss0==0 & miss1==0
gen _rank0_rewt = __rank0_rewt/N if  miss0==0 & miss1==0
by women surv79 faminc0_nm: egen rank0_rewt = mean(_rank0_rewt) if  miss0==0 & miss1==0
 replace rank0_rewt = 100*rank0_rewt
gen perc66_rewt = rank0_rewt*(1-surv79)
gen perc79_rewt = rank0_rewt*surv79


* Family Income Rank in Kid Generation
gen faminc1_nm = faminc1
 replace faminc1_nm = . if !(miss0==0 & miss1==0)
set sortseed 6688571
sort women surv79 faminc1_nm
by women surv79: gen __rank1_rewt = sum(rewt_marr) if  miss0==0 & miss1==0
gen _rank1_rewt = __rank1_rewt/N if  miss0==0 & miss1==0
bys women surv79 faminc1_nm: egen rank1_rewt = mean(_rank1_rewt) if  miss0==0 & miss1==0
replace rank1_rewt = 100*rank1_rewt

drop N faminc0_nm faminc1_nm

 
* Rank-rank (Re-weight check)
reg rank1_rewt perc66_rewt perc79_rewt surv79 women [w=rewt_marr] , cluster(hhid)
eststo rank_p_rewt
test perc79_rewt=perc66_rewt
estadd scalar p = r(p): rank_p_rewt
gen s=e(sample)
count if surv79==0 & s==1
estadd scalar N66 = r(N): rank_p_rewt
count if surv79==1 & s==1
estadd scalar N79 = r(N): rank_p_rewt
drop s
lincom perc79_rewt-perc66_rewt
estadd scalar diff = r(estimate): rank_p_rewt
estadd scalar se = r(se): rank_p_rewt

reg rank1_rewt perc66_rewt perc79_rewt surv79 if women==1 [w=rewt_marr] , cluster(hhid)
eststo rank_p_rewt_w
test perc79_rewt=perc66_rewt
estadd scalar p = r(p): rank_p_rewt_w
gen s=e(sample)
count if surv79==0 & s==1
estadd scalar N66 = r(N): rank_p_rewt_w
count if surv79==1 & s==1
estadd scalar N79 = r(N): rank_p_rewt_w
drop s
lincom perc79_rewt-perc66_rewt
estadd scalar diff = r(estimate): rank_p_rewt_w
estadd scalar se = r(se): rank_p_rewt_w

reg rank1_rewt perc66_rewt perc79_rewt surv79 if women==0 [w=rewt_marr] , cluster(hhid)
eststo rank_p_rewt_m
test perc79_rewt=perc66_rewt
estadd scalar p = r(p): rank_p_rewt_m
gen s=e(sample)
count if surv79==0 & s==1
estadd scalar N66 = r(N): rank_p_rewt_m
count if surv79==1 & s==1
estadd scalar N79 = r(N): rank_p_rewt_m
drop s
lincom perc79_rewt-perc66_rewt
estadd scalar diff = r(estimate): rank_p_rewt_m
estadd scalar se = r(se): rank_p_rewt_m
 
 
 
* IGE (Re-weight check)
reg lfaminc1 loginc66 loginc79 surv79 women [w=rewt_marr], cluster(hhid)
eststo IGE_p_rewt
test loginc79=loginc66
estadd scalar p = r(p): IGE_p_rewt
gen s=e(sample)
count if surv79==0 & s==1
estadd scalar N66 = r(N): IGE_p_rewt
count if surv79==1 & s==1
estadd scalar N79 = r(N): IGE_p_rewt
drop s
lincom loginc79-loginc66
estadd scalar diff = r(estimate): IGE_p_rewt
estadd scalar se = r(se): IGE_p_rewt

reg lfaminc1 loginc66 loginc79 surv79 if women==1 [w=rewt_marr], cluster(hhid)
eststo IGE_p_rewt_w
test loginc79=loginc66
estadd scalar p = r(p): IGE_p_rewt_w
gen s=e(sample)
count if surv79==0 & s==1
estadd scalar N66 = r(N): IGE_p_rewt_w
count if surv79==1 & s==1
estadd scalar N79 = r(N): IGE_p_rewt_w
drop s
lincom loginc79-loginc66
estadd scalar diff = r(estimate): IGE_p_rewt_w
estadd scalar se = r(se): IGE_p_rewt_w

reg lfaminc1 loginc66 loginc79 surv79 if women==0 [w=rewt_marr], cluster(hhid)
eststo IGE_p_rewt_m
test loginc79=loginc66
estadd scalar p = r(p): IGE_p_rewt_m
gen s=e(sample)
count if surv79==0 & s==1
estadd scalar N66 = r(N): IGE_p_rewt_m
count if surv79==1 & s==1
estadd scalar N79 = r(N): IGE_p_rewt_m
drop s
lincom loginc79-loginc66
estadd scalar diff = r(estimate): IGE_p_rewt_m
estadd scalar se = r(se): IGE_p_rewt_m
 



gen ownrank66 = ownrank*(1-surv79)
gen ownrank79 = ownrank*surv79



reg  rank1  ownrank66 ownrank79 surv79  women unmarried [w=weight] if share_married==100, cluster(hhid)
eststo assort
test ownrank66 =ownrank79
estadd scalar p = r(p): assort
gen s=e(sample)
count if surv79==0 & s==1
estadd scalar N66 = r(N): assort
count if surv79==1 & s==1
estadd scalar N79 = r(N): assort
lincom ownrank79-ownrank66
estadd scalar diff = r(estimate): assort
estadd scalar se = r(se): assort
drop s


reg  rank1  ownrank66 ownrank79 surv79  unmarried [w=weight] if share_married==100 & women==1, cluster(hhid)
eststo assort_w
test ownrank66 =ownrank79
estadd scalar p = r(p): assort_w
gen s=e(sample)
count if surv79==0 & s==1
estadd scalar N66 = r(N): assort_w
count if surv79==1 & s==1
estadd scalar N79 = r(N): assort_w
lincom ownrank79-ownrank66
estadd scalar diff = r(estimate): assort_w
estadd scalar se = r(se): assort_w
drop s


reg  rank1  ownrank66 ownrank79 surv79  unmarried [w=weight] if share_married==100 & women==0, cluster(hhid)
eststo assort_m
test ownrank66 =ownrank79
estadd scalar p = r(p): assort_m
gen s=e(sample)
count if surv79==0 & s==1
estadd scalar N66 = r(N): assort_m
count if surv79==1 & s==1
estadd scalar N79 = r(N): assort_m
lincom ownrank79-ownrank66
estadd scalar diff = r(estimate): assort_m
estadd scalar se = r(se): assort_m
drop s

gen lown66 = lown*(1-surv79)
gen lown79 = lown*surv79



reg  lfaminc1  lown66 lown79 surv79  women unmarried [w=weight] if share_married==100, cluster(hhid)
eststo assort_ige
test lown66=lown79
estadd scalar p = r(p): assort_ige
gen s=e(sample)
count if surv79==0 & s==1
estadd scalar N66 = r(N): assort_ige
count if surv79==1 & s==1
estadd scalar N79 = r(N): assort_ige
lincom lown79-lown66
estadd scalar diff = r(estimate): assort_ige
estadd scalar se = r(se): assort_ige
drop s

reg  lfaminc1  lown66 lown79 surv79  unmarried [w=weight] if share_married==100 & women==1, cluster(hhid)
eststo assort_ige_w
test lown66=lown79
estadd scalar p = r(p): assort_ige_w
gen s=e(sample)
count if surv79==0 & s==1
estadd scalar N66 = r(N): assort_ige_w
count if surv79==1 & s==1
estadd scalar N79 = r(N): assort_ige_w
drop s

reg  lfaminc1  lown66 lown79 surv79  unmarried [w=weight] if share_married==100 & women==0, cluster(hhid)
eststo assort_ige_m
test lown66=lown79
estadd scalar p = r(p): assort_ige_m
gen s=e(sample)
count if surv79==0 & s==1
estadd scalar N66 = r(N): assort_ige_m
count if surv79==1 & s==1
estadd scalar N79 = r(N): assort_ige_m
drop s


* Re-gen ownrank using re-weights
gen N = .
 tab n  if surv79==0 & women==0 & miss0==0 & miss1==0  & miss1_l750==0 [w=rewt_marr]
 replace N = r(N) if surv79==0 & women==0 & miss0==0 & miss1==0  & miss1_l750==0
 tab n  if surv79==0 & women==1  & miss0==0 & miss1==0   & miss1_l750==0 [w=rewt_marr]
 replace N = r(N) if surv79==0 & women==1 & miss0==0 & miss1==0   & miss1_l750==0
 tab n  if surv79==1 & women==0  & miss0==0 & miss1==0   & miss1_l750==0 [w=rewt_marr]
 replace N = r(N) if surv79==1 & women==0 & miss0==0 & miss1==0   & miss1_l750==0
 tab n  if surv79==1 & women==1 & miss0==0 & miss1==0   & miss1_l750==0 [w=rewt_marr]
 replace N = r(N) if surv79==1 & women==1 & miss0==0 & miss1==0   & miss1_l750==0


gen owninc_nm = owninc
replace owninc_nm = . if !(miss0==0 & miss1==0 & miss1_l750==0 )
set sortseed 6688571
sort women surv79 owninc_nm
by women surv79: gen __ownrank_rewt = sum(rewt_marr) if  miss0==0 & miss1==0 & miss1_l750==0
gen _ownrank_rewt = __ownrank_rewt/N if  miss0==0 & miss1_l750==0
bys women surv79 owninc_nm: egen ownrank_rewt = mean(_ownrank_rewt) if  miss0==0 & miss1==0 & miss1_l750==0
replace ownrank_rewt = 100*ownrank_rewt
gen ownrank_rewt66 = ownrank_rewt*(1-surv79)
gen ownrank_rewt79 = ownrank_rewt*surv79



reg  rank1  ownrank_rewt66 ownrank_rewt79 surv79  women unmarried [w=rewt_marr] , cluster(hhid)
eststo assort_rewt
test ownrank_rewt66 =ownrank_rewt79
estadd scalar p = r(p): assort_rewt
gen s=e(sample)
count if surv79==0 & s==1
estadd scalar N66 = r(N): assort_rewt
count if surv79==1 & s==1
estadd scalar N79 = r(N): assort_rewt
lincom ownrank_rewt79-ownrank_rewt66
estadd scalar diff = r(estimate): assort_rewt
estadd scalar se = r(se): assort_rewt
drop s


reg  rank1  ownrank_rewt66 ownrank_rewt79 surv79  unmarried if women==1 [w=rewt_marr] , cluster(hhid)
eststo assort_rewt_w
test ownrank_rewt66 =ownrank_rewt79
estadd scalar p = r(p): assort_rewt_w
gen s=e(sample)
count if surv79==0 & s==1
estadd scalar N66 = r(N): assort_rewt_w
count if surv79==1 & s==1
estadd scalar N79 = r(N): assort_rewt_w
lincom ownrank_rewt79-ownrank_rewt66
estadd scalar diff = r(estimate): assort_rewt_w
estadd scalar se = r(se): assort_rewt_w
drop s

reg  rank1  ownrank_rewt66 ownrank_rewt79 surv79  unmarried if women==1 [w=rewt_marr] , cluster(hhid)
eststo assort_rewt_m
test ownrank_rewt66 =ownrank_rewt79
estadd scalar p = r(p): assort_rewt_m
gen s=e(sample)
count if surv79==0 & s==1
estadd scalar N66 = r(N): assort_rewt_m
count if surv79==1 & s==1
estadd scalar N79 = r(N): assort_rewt_m
lincom ownrank_rewt79-ownrank_rewt66
estadd scalar diff = r(estimate): assort_rewt_m
estadd scalar se = r(se): assort_rewt_m
drop s




reg  lfaminc1  lown66 lown79 surv79  women unmarried [w=rewt_marr] , cluster(hhid)
eststo assort_ige_rewt
test lown66=lown79
estadd scalar p = r(p): assort_ige_rewt
gen s=e(sample)
count if surv79==0 & s==1
estadd scalar N66 = r(N): assort_ige_rewt
count if surv79==1 & s==1
estadd scalar N79 = r(N): assort_ige_rewt
lincom lown79-lown66
estadd scalar diff = r(estimate): assort_ige_rewt
estadd scalar se = r(se): assort_ige_rewt
drop s

reg  lfaminc1  lown66 lown79 surv79   unmarried if women==1 [w=rewt_marr] , cluster(hhid)
eststo assort_ige_rewt_w
test lown66=lown79
estadd scalar p = r(p): assort_ige_rewt_w
gen s=e(sample)
count if surv79==0 & s==1
estadd scalar N66 = r(N): assort_ige_rewt_w
count if surv79==1 & s==1
estadd scalar N79 = r(N): assort_ige_rewt_w
lincom lown79-lown66
estadd scalar diff = r(estimate): assort_ige_rewt_w
estadd scalar se = r(se): assort_ige_rewt_w
drop s

reg  lfaminc1  lown66 lown79 surv79   unmarried if women==0 [w=rewt_marr] , cluster(hhid)
eststo assort_ige_rewt_m
test lown66=lown79
estadd scalar p = r(p): assort_ige_rewt_m
gen s=e(sample)
count if surv79==0 & s==1
estadd scalar N66 = r(N): assort_ige_rewt_m
count if surv79==1 & s==1
estadd scalar N79 = r(N): assort_ige_rewt_m
lincom lown79-lown66
estadd scalar diff = r(estimate): assort_ige_rewt_m
estadd scalar se = r(se): assort_ige_rewt_m
drop s





#delimit ;
estout  married married_rewt rank_p_rewt assort assort_rewt  
	using  "${results_dir}table3.txt",  replace
	keep(perc66 perc79) 
	rename(ownrank66 perc66 ownrank79 perc79  perc66_rewt perc66 perc79_rewt perc79 ownrank_rewt66 perc66 ownrank_rewt79 perc79)
	cells(b(star fmt(3))  se(par fmt(3))) 
	collabels(,none) stat(diff se p N66 N79) stardrop(*) ;	


estout  married_ige married_ige_rewt IGE_p_rewt assort_ige assort_ige_rewt 
	using  "${results_dir}tableA14.txt", replace
	keep(loginc66 loginc79) 
	rename(lown66 loginc66 lown79 loginc79)
	cells(b(star fmt(3))  se(par fmt(3))) 
	collabels(,none) stat(diff se p N66 N79) stardrop(*) ;	
	
	
estout  married_w married_rewt_w rank_p_rewt_w  assort_w assort_rewt_w 
	using  "${results_dir}tableA15.txt",  replace
	keep(perc66 perc79) 
	rename(ownrank66 perc66 ownrank79 perc79  perc66_rewt perc66 perc79_rewt perc79 ownrank_rewt66 perc66 ownrank_rewt79 perc79)
	cells(b(star fmt(3))  se(par fmt(3))) 
	collabels(,none) stat(diff se p N66 N79) stardrop(*) ;	


estout  married_ige_w married_ige_rewt_w IGE_p_rewt_w assort_ige_w assort_ige_rewt_w  
	using  "${results_dir}tableA15.txt", append
	keep(loginc66 loginc79) 
	rename(lown66 loginc66 lown79 loginc79)
	cells(b(star fmt(3))  se(par fmt(3))) 
	collabels(,none) stat(diff se p N66 N79) stardrop(*) ;	
	
estout  married_m married_rewt_m rank_p_rewt_m  assort_m assort_rewt_m  
	using  "${results_dir}tableA16.txt",  replace
	keep(perc66 perc79) 
	rename(ownrank66 perc66 ownrank79 perc79  perc66_rewt perc66 perc79_rewt perc79 ownrank_rewt66 perc66 ownrank_rewt79 perc79)
	cells(b(star fmt(3))  se(par fmt(3))) 
	collabels(,none) stat(diff se p N66 N79) stardrop(*) ;	


estout  married_ige_m married_ige_rewt_m IGE_p_rewt_m  assort_ige_m assort_ige_rewt_m  
	using  "${results_dir}tableA16.txt", append
	keep(loginc66 loginc79) 
	rename(lown66 loginc66 lown79 loginc79)
	cells(b(star fmt(3))  se(par fmt(3))) 
	collabels(,none) stat(diff se p N66 N79) stardrop(*) ;		
	
#delimit cr	








exit











exit
